<?php
/*
 * Created on Jun 11, 2010
 *
 * To change the template for this generated file go to
 * Window - Preferences - PHPeclipse - PHP - Code Templates
 */
 class LoginController extends AppController {

	var $name = 'Login';
	var $uses = null;	
	
	function index() {
		if(!empty($this->data)){
			$this->loadModel('User');
			$userModel = new User();
			$user = $userModel->find('first',array('conditions'=>array('username'=>$this->data['User']['username'],'password'=>$this->data['User']['password'])));
			if(!empty($user)){
				$this->Session->write('authorizedUser',$user);
				$this->redirect('/worklogs/work');
			}
		}
		$this->Session->destroy('authorizedUser');
		$this->layout = 'login';		
	}
	
	function access_denied() {
		$this->set('error_message','Access Denied');
		$this->layout = 'login';
		$this->render('index');
	}
	
	
}
 
?>
